package com.youlai.boot.system.controller;

import com.youlai.boot.system.service.SysYouqitouziService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.system.model.form.SysYouqitouziForm;
import com.youlai.boot.system.model.query.SysYouqitouziQuery;
import com.youlai.boot.system.model.vo.SysYouqitouziVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 油气项目后评价前端控制层
 *
 * @author 李文兵
 * @since 2025-05-29 11:14
 */
@Tag(name = "油气项目后评价接口")
@RestController
@RequestMapping("/api/v1/sysYouqitouzis")
@RequiredArgsConstructor
public class SysYouqitouziController  {

    private final SysYouqitouziService sysYouqitouziService;

    @Operation(summary = "油气项目后评价分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('system:sysYouqitouzi:query')")
    public PageResult<SysYouqitouziVO> getSysYouqitouziPage(SysYouqitouziQuery queryParams ) {
        IPage<SysYouqitouziVO> result = sysYouqitouziService.getSysYouqitouziPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增油气项目后评价")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('system:sysYouqitouzi:add')")
    public Result<Void> saveSysYouqitouzi(@RequestBody @Valid SysYouqitouziForm formData ) {
        boolean result = sysYouqitouziService.saveSysYouqitouzi(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取油气项目后评价表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('system:sysYouqitouzi:edit')")
    public Result<SysYouqitouziForm> getSysYouqitouziForm(
        @Parameter(description = "油气项目后评价ID") @PathVariable Long id
    ) {
        SysYouqitouziForm formData = sysYouqitouziService.getSysYouqitouziFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改油气项目后评价")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('system:sysYouqitouzi:edit')")
    public Result<Void> updateSysYouqitouzi(
            @Parameter(description = "油气项目后评价ID") @PathVariable Long id,
            @RequestBody @Validated SysYouqitouziForm formData
    ) {
        boolean result = sysYouqitouziService.updateSysYouqitouzi(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除油气项目后评价")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('system:sysYouqitouzi:delete')")
    public Result<Void> deleteSysYouqitouzis(
        @Parameter(description = "油气项目后评价ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = sysYouqitouziService.deleteSysYouqitouzis(ids);
        return Result.judge(result);
    }
}
